/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sluggard.tangela.core;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JOptionPane;

/**
 *
 * @author Frank
 */
public class SubmitButton extends JButton {

	public SubmitButton() {
		super();
		setText("提交");
		addActionListener(new SubmitAction());
	}

	public SubmitButton(Action a) {
		super(a);
		// TODO Auto-generated constructor stub
	}

	public SubmitButton(Icon icon) {
		super(icon);
		// TODO Auto-generated constructor stub
	}

	public SubmitButton(String text, Icon icon) {
		super(text, icon);
		// TODO Auto-generated constructor stub
	}

	public SubmitButton(String text) {
		super(text);
	}
	
	private class SubmitAction implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent evt) {
			String content = Container.getMainSelf().getInputText().getText();
			if(content.trim().length() == 0) {
				new Thread(new Runnable() {
					
					@Override
					public void run() {
						JOptionPane.showMessageDialog(Container.tempFrame, "请不要输入空消息!");
					}
				}).start();
			} else {
				Container.send(content);
				Container.getMainSelf().getInputText().setText("");
			}
		}
		
	}

}
